package com.javasm.mb_store_api_final.sys_control.rolecontrol.sys_role.controller;

import com.javasm.common.R;
import com.javasm.mb_store_api_final.sys_control.rolecontrol.sys_role.entity.SysRole;
import com.javasm.mb_store_api_final.sys_control.rolecontrol.sys_role.service.SysRoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author Lx
 * @version 0.1
 * @className RoleControl
 * @date 2024/7/31 9:43
 * @description
 * @since jdk11
 */
@RestController
@RequestMapping("/role")
public class RoleControl {

    @Resource
    SysRoleService roleService;

    @GetMapping("/query")
    public R selectAllRole() {
       List<SysRole> sysRoles = roleService.selectAllRole();
        return R.ok(sysRoles);
    }

    @GetMapping("/paramList")
    public R paramList() {
        Map<String, Set<String>> map = roleService.paramList();
        return R.ok(map);
    }
    @GetMapping("/queryBy")
    public R queryList(SysRole role) {
                List<SysRole> sysRoles = roleService.queryBy(role);
        return R.ok(sysRoles);
    }

    @PostMapping("/add")
    public R addRole(SysRole role) {
        roleService.addRole(role);
        return R.ok();
    }

    @PostMapping("/update")
    public R updateRole(SysRole role) {
        roleService.updateRole(role.getRoleId(),role);
        return R.ok();
    }

    @DeleteMapping("/delete/{roleId}")
    public R deleteRole(@PathVariable Integer roleId) {
        roleService.deleteByRId(roleId);
        return R.ok();
    }
    @GetMapping("/getTatol")
    public R getTatol() {
        long count =  roleService.countall();
        return R.ok(count);
    }
}
